在 android 中将动态数字放在形状上
Putting dynamic numbers on a shape in android
我想要的:
I want to create shapes (shapes can be rectangle, circle or any) and
put some random numbers to that shape.
我做了什么:
I've already created shapes using custom view.
问题:
How to put random numbers on shapes dynamically?
注意:每次打开应用程序时数字的位置应该不同。
我绘制形状的代码是:
package com.example.myb.bazibadast;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;
public class YeknafareActivity_layout extends View {
Paint black_paintbrushstroke;
Path Hand;
public YeknafareActivity_layout(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
black_paintbrushstroke = new Paint();
black_paintbrushstroke.setColor(Color.BLACK);
black_paintbrushstroke.setStyle(Paint.Style.STROKE);
black_paintbrushstroke.setStrokeWidth(4);
Hand = new Path();
Hand.moveTo(225, 844); // A
Hand.lineTo(191, 675);
Hand.moveTo(191, 675); // B
Hand.lineTo(114, 412);
Hand.moveTo(114, 412); // C
Hand.lineTo(147, 409);
Hand.moveTo(147, 409); // D
Hand.lineTo(235, 591);
Hand.moveTo(235, 591); // E
Hand.lineTo(179, 279);
Hand.moveTo(179, 279); // F
Hand.lineTo(222, 279);
Hand.moveTo(222, 279); // G
Hand.lineTo(300, 534);
Hand.moveTo(300, 534); // H
Hand.lineTo(308, 186);
Hand.moveTo(308, 186); // I
Hand.lineTo(341, 187);
Hand.moveTo(341, 187); // J
Hand.lineTo(382, 513);
Hand.moveTo(382, 513); // K
Hand.lineTo(427, 212);
Hand.moveTo(427, 212); // L
Hand.lineTo(460, 216);
Hand.moveTo(460, 216); // M
Hand.lineTo(462, 536);
Hand.moveTo(462, 536); // O
Hand.lineTo(476, 613);
Hand.moveTo(476, 613); // P
Hand.lineTo(507, 662);
Hand.moveTo(507, 662); // Q
Hand.lineTo(593, 501);
Hand.moveTo(593, 501); // R
Hand.lineTo(628, 492);
Hand.moveTo(628, 492); // S
Hand.lineTo(645, 511);
Hand.moveTo(645, 511); // T
Hand.lineTo(470, 960);
Hand.moveTo(470, 960); // U
Hand.lineTo(386, 989);
Hand.moveTo(386, 989); // V
Hand.lineTo(280, 947);
Hand.lineTo(225, 844);
canvas.drawPath(Hand, black_paintbrushstroke);
}
对于那些和我有同样问题的人,在下面link我得到了一个以另一种方式解决问题的答案。但是,我稍微更改了答案以符合我的需要。
因此,如果您有同样的问题,请查看下面 link:
中的答案
我想要的:
I want to create shapes (shapes can be rectangle, circle or any) and put some random numbers to that shape.
我做了什么:
I've already created shapes using custom view.
问题:
How to put random numbers on shapes dynamically?
注意:每次打开应用程序时数字的位置应该不同。
我绘制形状的代码是:
package com.example.myb.bazibadast;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;
public class YeknafareActivity_layout extends View {
Paint black_paintbrushstroke;
Path Hand;
public YeknafareActivity_layout(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
black_paintbrushstroke = new Paint();
black_paintbrushstroke.setColor(Color.BLACK);
black_paintbrushstroke.setStyle(Paint.Style.STROKE);
black_paintbrushstroke.setStrokeWidth(4);
Hand = new Path();
Hand.moveTo(225, 844); // A
Hand.lineTo(191, 675);
Hand.moveTo(191, 675); // B
Hand.lineTo(114, 412);
Hand.moveTo(114, 412); // C
Hand.lineTo(147, 409);
Hand.moveTo(147, 409); // D
Hand.lineTo(235, 591);
Hand.moveTo(235, 591); // E
Hand.lineTo(179, 279);
Hand.moveTo(179, 279); // F
Hand.lineTo(222, 279);
Hand.moveTo(222, 279); // G
Hand.lineTo(300, 534);
Hand.moveTo(300, 534); // H
Hand.lineTo(308, 186);
Hand.moveTo(308, 186); // I
Hand.lineTo(341, 187);
Hand.moveTo(341, 187); // J
Hand.lineTo(382, 513);
Hand.moveTo(382, 513); // K
Hand.lineTo(427, 212);
Hand.moveTo(427, 212); // L
Hand.lineTo(460, 216);
Hand.moveTo(460, 216); // M
Hand.lineTo(462, 536);
Hand.moveTo(462, 536); // O
Hand.lineTo(476, 613);
Hand.moveTo(476, 613); // P
Hand.lineTo(507, 662);
Hand.moveTo(507, 662); // Q
Hand.lineTo(593, 501);
Hand.moveTo(593, 501); // R
Hand.lineTo(628, 492);
Hand.moveTo(628, 492); // S
Hand.lineTo(645, 511);
Hand.moveTo(645, 511); // T
Hand.lineTo(470, 960);
Hand.moveTo(470, 960); // U
Hand.lineTo(386, 989);
Hand.moveTo(386, 989); // V
Hand.lineTo(280, 947);
Hand.lineTo(225, 844);
canvas.drawPath(Hand, black_paintbrushstroke);
}
对于那些和我有同样问题的人,在下面link我得到了一个以另一种方式解决问题的答案。但是,我稍微更改了答案以符合我的需要。 因此,如果您有同样的问题,请查看下面 link:
中的答案